#include "admin.h"
#include "ui_admin.h"
#include "widget.h"


Admin::Admin(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Admin)
{
    ui->setupUi(this);
    b = new Widget;
    b->socket_data_accept();

    this->setWindowFlag(Qt::FramelessWindowHint);//去掉窗口标题
    QPixmap *pix = new QPixmap(":/picture/login.jpg");//设置图片
    QSize sz = ui->label_image->size();
    ui->label_image->setPixmap(pix->scaled(sz));

}

Admin::~Admin()
{
    delete ui;
}

//获取密码登录
void Admin::on_enter_clicked()
{
   QString username = ui->account->text();
   QString password = ui->passwd->text();
   QString sql = QString("select * from admin where username='%1' and password='%2'").arg(username).arg(password);
   QSqlQuery query(sql);
   if(!query.next()){
       qDebug() << "LOGIN ERROR";
       QMessageBox::information(this,"登录认证","登录失败，账号或密码错误");
   }else{
       qDebug() << "LOGIN SUCCESS";
       QMessageBox::information(this,"登录认证","登录成功");
       //登录成功后跳转到其他页面
       b->show();
       this->close();

       connect(this,&Admin::sendMsg,b,&Widget::recvMsg);
       emit sendMsg(username);
   }

}



void Admin::on_signup_clicked()
{
    this->close();
    signup *s = new signup;
    s->show();
}

void Admin::on_quit_clicked()
{
    this->close();
}
